﻿/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef GAME_GAME_OBJECTMANAGER_H_
#define GAME_GAME_OBJECTMANAGER_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <boost/unordered_map.hpp>
#include <NodeCpp/Macros.h>
#include <NodeCpp/Singleton.h>
#include "Game/SQLStorages.h"
#include "Game/Creature.h"
#include "Game/ItemPrototype.h"
#include "Game/PlayerDefines.h"
#include "Game/ObjectManagerDefine.h"
using NodeCpp::Singleton;

class ObjectManager
{
public:
    ObjectManager(void);
    ~ObjectManager(void);

    bool LoadCreatureTemplates(void);
    bool LoadInstanceTemplate(void);
    bool LoadItemPrototypes(void);
    bool LoadPlayerInfo(void);

    /* 数据获取接口 */
    const struct CreatureInfo* GetCreatureInfo(std::uint32_t _ID);
    const struct ItemPrototype* GetItemPrototype(std::uint32_t _ID);
    const struct PlayerInfo* GetPlayerInfo(std::uint32_t _Race, std::uint32_t _Class);

    std::uint32_t GeneratePlayerLowGuid(void) { return CharGuids_.Generate(); }

    static bool NormalizePlayerName(std::string& _Name);
    static std::uint8_t CheckPlayerName(const std::string& _Name, bool _Create = false);
    bool IsReservedName(const std::string& _Name);
    ObjectGuid GetPlayerGuidByName(const std::string& _Name);
    void AddPlayerGuidByName(const std::string& _Name, std::uint32_t _GuidLow);

private:
    bool _LoadPlayreCreateInfo(void);
    bool _LoadPlayreCreateInfoItem(void);
    bool _LoadPlayreCreateInfoSpell(void);
    bool _LoadPlayreCreateInfoAction(void);
    bool _LoadPlayerClassLevelStats(void);
    bool _LoadPlayerLevelStats(void);
    bool _LoadPlayerXpForLevel(void);
    bool _LoadPlayerNames(void);


    ///////////////////////////////////////////////////////////////////////////
    // 角色配置数据
    typedef std::vector<std::uint32_t> PlayerXPperLevel;
    // 各种族职业的角色的(出生点/Model/Item/Spell/Action)数据
    PlayerInfo PlayerInfo_[MAX_RACES][MAX_CLASSES];
    // 各职业在每个等级的基础生命值/魔法值
    PlayerClassInfo PlayerClassInfo_[MAX_CLASSES];
    // 各等级经验数据
    PlayerXPperLevel PlayerXPperLevel_;

    ///////////////////////////////////////////////////////////////////////////
    // GUID数据
    typedef boost::unordered_map<std::string, std::uint32_t> Name2Guid;
    Name2Guid Name2Guid_;
    ObjectGuidGenerator<HIGHGUID_PLAYER> CharGuids_;
    DISALLOW_COPY_AND_ASSIGN(ObjectManager);
};
#define sObjMgr Singleton<ObjectManager>::Instance()

#endif // GAME_GAME_OBJECTMANAGER_H_
